// pages/z_job_intention/index.js
const app = getApp(), core = require('../../utils/core');
Page({

  /**
   * 页面的初始数据
   */
  data: {
	job_intentions:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
	this.fetchJobIntentions();
  },

  fetchJobIntentions(){
	core.get({url:'xilujob.resume/job_intention',data:{},success:ret=>{
		this.setData({
			job_intentions:ret.data
		})
	  }});
  },

  bindEditJobIntention(event) {
	wx.navigateTo({
		url: '/pages/my_resume/job_intention',
		events: {
		  dataTransfer: data => {
			let job_intention = data.model, index = null, job_intentions = this.data.job_intentions;
			for(let i=0;i<job_intentions.length;i++) {
			  if(job_intentions[i].id==job_intention.id) {
				index = i;
				break;
			  }
			}
			if(index===null) {
			  job_intentions.push(job_intention);
			}else {
			  job_intentions.splice(index, 1, job_intention);
			}
			job_intentions.sort((a,b)=>{
			  return a.start > b.start ? -1 : 1;
			});
			this.setData({job_intentions: job_intentions});
			//app.eventBus.emit(app.Events.UcenterInfoCompleteChange, data.complete_percent);
		  }
		},
		success: res => {
		  res.eventChannel.emit('dataTransfer', {model: event.currentTarget.dataset.model||{}});
		}
	  });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  }
})